import Vue from 'vue'
import Router from 'vue-router'
import routes from './routers'
import store from '@/store'
import iView from 'view-design'
import { setToken, getToken, canTurnTo, setTitle } from '@/libs/util'
import config from '@/config'
const { homeName } = config
const LOGIN_PAGE_NAME = 'login'
Vue.use(Router)
const router = new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  iView.LoadingBar.start()
  next()
  // const token = localStorage.getItem('token');
  //   if (!token && to.name != LOGIN_PAGE_NAME) {
  //       iView.LoadingBar.finish();
  //       next({
  //           name: LOGIN_PAGE_NAME
  //       });
  //   } else {
  //       iView.LoadingBar.finish();
  //       next()
  //   }
})

router.afterEach(to => {
  setTitle(to, router.app)
  iView.LoadingBar.finish()
  window.scrollTo(0, 0)
})

export default router
